package cn.kevinproject.dingtalk_robot.client;

import cn.kevinproject.dingtalk_robot.msg.Message;
import com.dingtalk.api.DingTalkClient;
import com.google.common.base.Throwables;
import com.taobao.api.ApiException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author kevin lau (双鹰)
 */
@Slf4j
@RequiredArgsConstructor
public class Producer {

    private final DingTalkClient dingTalkClient;

    public void sendMsg(Message message) {
        try {
            dingTalkClient.execute(message.buildRequest());
        } catch (ApiException e) {
            log.error("msg send error cause:{}", Throwables.getStackTraceAsString(e));
        }
    }
}
